package com.stations.task;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.util.StrUtil;
import com.stations.EntranceApplication;
import com.stations.common.utils.SystemInfoUtils;
import com.stations.domain.SysConfig;
import com.stations.domain.TTransmitter;
import com.stations.domain.TTransmitterProgram;
import com.stations.domain.TTransmitterTask;
import com.stations.mapper.SysConfigMapper;
import com.stations.mapper.TTransmitterProgramMapper;
import com.stations.service.TransmitterSendService;
import de.schlichtherle.license.LicenseContentException;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;


/**
 * ProgramTask
 *
 * @author jintao
 * @version 2023/10/12 14:56
 **/
@Component
@EnableScheduling
@Slf4j
public class LicenseTask {

    @Resource
    private SysConfigMapper sysConfigMapper;

    @SneakyThrows
    @Scheduled(cron = "0 0 0 * * ?")
    public void task() {
        try {
            SysConfig license = sysConfigMapper.selectByCode("license");
            String configValue;
            if (license != null) {
                configValue = license.getConfigValue();
                if (StrUtil.isEmpty(configValue)) {
                    log.error("系统未授权,请联系厂商进行授权,侵权必究");
                    throw new LicenseContentException("系统未授权,请联系厂商进行授权,侵权必究");
                }
            } else {
                log.error("系统未授权,请联系厂商进行授权,侵权必究");
                throw new LicenseContentException("系统未授权,请联系厂商进行授权,侵权必究");
            }
            SystemInfoUtils.checkLicense(configValue);
        }catch (Exception e){
            log.error("系统检测授权信息有误-错误信息:{}",Arrays.toString(e.getStackTrace()));
            Process netStopStations = Runtime.getRuntime().exec("NET STOP stations");
            netStopStations.getOutputStream().close();
        }
    }
}
